Score 4
拓扑排序
Author 陈越
Organization 浙江大学
下列代码的功能是对一个给定的图G执行拓扑排序,其中TopNum[]从1开始记录拓扑序。
void Topsort( Graph G )
{
Queue Q;
Vertex V, W;
NodePtr ptr;
int counter = 0;
Q = CreateEmptyQueue(NumVertex);
for ( V=0; V<G->NumV; V++ )
if ( Indegree[V] == 0 )
Enqueue(V, Q);
while ( !IsEmpty(Q) ){
V = Dequeue( Q );
TopNum[V] = 2 point(s);
for ( ptr=G->List[V]; ptr; ptr=ptr->Next) {
W = ptr->Vertex;
if ( 2 point(s) == 0 )
Enqueue(W, Q);
}
}
if ( counter != NumVertex )
printf("ERROR: Graph has a cycle.\n");
DisposeQueue(Q);
}
Judge Result
Partially Accepted
Score
2 Point(s)
Score 6
单链表逆转
Author DS课程组
Organization 浙江大学
下列代码的功能是返回带头结点的单链表L的逆转链表。
List Reverse( List L )
{
Position Old_head, New_head, Temp;
New_head = NULL;
Old_head = L->Next;
while ( Old_head ) {
Temp = Old_head->Next;
3 point(s);
New_head = Old_head;
Old_head = Temp;
}
3 point(s);
return L;
}
Judge Result
Multiple Errors
Score
0 Point(s)
The answer has ended. It is only for browsing the problem